\testfile{pgfplotstest.align.tex}
\testsection{Anchors, alignment, baselines, sub nodes}%
\testsubsection{Baseline alignment}
\noindent
\starttikzpicture[baseline]
	\startaxis[width=6cm,xlabel=An x label]
		\smallplotstest
	\stopaxis
\stoptikzpicture
\starttikzpicture[baseline]
	\startaxis[width=6cm,xlabel={\switchtobodyfont[15pt] An x label}]
		\smallplotstest
	\stopaxis
\stoptikzpicture

\testsubsection{Baseline alignment and externalized graphics}
One needs {\tt beginpgfgraphicnamed} around the complete paragraph, so this here doesn't work (see source code):

\beginpgfgraphicnamed{baselinetesta}
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel=An x label]
	\smallplotstest
\stopaxis
\stoptikzpicture
\endpgfgraphicnamed
%
%
\beginpgfgraphicnamed{baselinetestb}
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel={\switchtobodyfont[15pt] An x label}]
	\smallplotstest
\stopaxis
\stoptikzpicture
\endpgfgraphicnamed

\testsubsection{Baseline alignment and externalized graphics II}
\beginpgfgraphicnamed{baselinetestc}
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel=An x label]
	\smallplotstest
\stopaxis
\stoptikzpicture
%
%
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel={\switchtobodyfont[15pt] An x label}]
	\smallplotstest
\stopaxis
\stoptikzpicture
\endpgfgraphicnamed

\testsubsection{Horizontal and Vertical alignment}
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel=An x label,ylabel=An y label]
	\smallplotstest
\stopaxis

\startscope[yshift=-4cm]
\startaxis[width=6cm,xlabel=An x label,ylabel={$\displaystyle\sum_{k=1}^n \frac 1n$}]
	\smallplotstest
\stopaxis
\stopscope

\node[fill=yellow,circle] at (0,0) {$(0,0)$};
\stoptikzpicture
%
%
\starttikzpicture[baseline]
\startaxis[width=6cm,xlabel={\switchtobodyfont[15pt] An x label}]
	\smallplotstest
\stopaxis

\startscope[yshift=-4cm]
\startaxis[width=6cm,xlabel={\switchtobodyfont[15pt] An x label},ylabel={$\displaystyle\sum_{k=1}^n \frac 1n$}]
	\smallplotstest
\stopaxis
\stopscope
\node[fill=yellow,circle] at (0,0) {$(0,0)$};
\stoptikzpicture

\testsubsection{Anchortest}
{
\def\plot#1{
	\vbox{\hsize=5cm
	#1:

	\pgfplotsset{every axis legend/.append style={at={(1.03,1)},anchor=north west}}
	\starttikzpicture
		\startaxis[
			width=5cm,
			anchor=#1,
			title=My title,
			xlabel=$x$,
			ylabel=$y$
		]
			\smallplotstest
			\addlegendentry{My plot}
		\stopaxis
		\pgfinterruptboundingbox
		\node[fill=yellow,circle] at (0,0) {$(0,0)$};
		\endpgfinterruptboundingbox
	\stoptikzpicture
	}
}%
\plot{outer center}
\plot{outer north}
\plot{outer north east}
\plot{outer east}
\plot{outer south east}
\plot{outer south}
\plot{outer south west}
\plot{outer west}
\plot{outer north west}
\plot{center}
\plot{north}
\plot{north east}
\plot{east}
\plot{south east}
\plot{south}
\plot{south west}
\plot{west}
\plot{north west}
\plot{above north}
\plot{above north east}
\plot{right of north east}
\plot{right of east}
\plot{right of south east}
\plot{below south east}
\plot{below south}
\plot{below south west}
\plot{left of south west}
\plot{left of west}
\plot{left of north west}
\plot{above north west}
}


\testsubsection{Accessing sub-nodes}
\starttikzpicture[baseline]%
	\node[circle,draw=black] at (0,0) {Origin};
	\startloglogaxis[
		anchor=north,
		name=firstplot,
		xlabel=Cost,
		ylabel=Error,
		y label style={name=myylabel},
		x label style={name=myxlabel},
		legend style={name=mylegend,
			row 1 column 2/.style={blue,name=firstentry}% doesn't work!
		}
	]
	\addplot plot coordinates {
		(5,     8.31160034e-02)
		(17,    2.54685628e-02)
		(49,    7.40715288e-03)
		(129,   2.10192154e-03)
		(321,   5.87352989e-04)
		(769,   1.62269942e-04)
		(1793, 4.44248889e-05)
		(4097, 1.20714122e-05)
		(9217, 3.26101452e-06)
	};
	\addplot plot coordinates {
		(7,     8.47178381e-02)
		(31,    3.04409349e-02)
		(111,   1.02214539e-02)
		(351,   3.30346265e-03)
		(1023,  1.03886535e-03)
		(2815,  3.19646457e-04)
		(7423,  9.65789766e-05)
		(18943, 2.87339125e-05)
		(47103, 8.43749881e-06)
	};
	\legend{Case 1\\Case 2\\}
	\stoploglogaxis

	\node[pin=45:legend] at (mylegend.center) {};
	\node[pin=-45:x label] at (myxlabel.center) {};
	\node[pin=180:y label] at (myylabel.center) {};
\stoptikzpicture%


\testsubsection{Funny bounding boxes}
\testsubsubsection{(my plot.below south west) rectangle (my plot.above north east)}
{
The following figure is centered:
\starttikzpicture%
	\pgfinterruptboundingbox
	\pgfplotsset{every axis legend/.append style={at={(1.03,1)},anchor=north west}}
	\startaxis[
		name=my plot,
		title=A title,
		xlabel={\switchtobodyfont[15pt] An x label},
		ylabel={$\displaystyle\sum_{k=1}^n \frac 1n$}
	]
		\smallplotstest
		\addlegendentry{My plot}
	\stopaxis
	\endpgfinterruptboundingbox

	\useasboundingbox (my plot.below south west) rectangle (my plot.above north east);
\stoptikzpicture%
}%
